home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATATYPE.SWG / 0016_Inverse Ordinal Types.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  896b  |  34 lines

  1. (*
  2. > is there any way to write an inverse Ord function for any type?
  3.  
  4. > Type Color = (RED, BLUE, GREEN, VIOLET, PURPLE);
  5. > Var Whatever : Color;
  6.  
  7. > Begin
  8. >   Writeln ('Red: ',Ord(Red); { Will print Red: 0 }
  9. >   Writeln ('Inverse of Ord of Red:,InvOrd(0,Color); { Should spit out RED }
  10. > End.
  11.  
  12. > For the function I had this in mind:
  13.  
  14. > Function InvOrd(TypeOrd : Integer; SpecifyType : SomeType) : SomeType;
  15. > Begin
  16. >   { What goes here? }
  17. > End.
  18.  
  19. In a running program, variables are not really accessed by name, but by
  20. address,  and their names don't show up in the final EXE.  The only way
  21. I know to do such a thing is to add:
  22. *)
  23.  
  24. Const
  25.   Red    = 1;
  26.   Purple = 5;
  27.   InvOrd : Array [Red..Purple] of String[6] =
  28.       ('Red', 'Blue', 'Green', 'Violet', 'Purple');
  29.  
  30. { And then access this array like: }
  31. begin
  32.   WriteLn('Inverse of Ord of Red:', InvOrd[Red]);
  33. end.
  34.